﻿#ifndef CUSTOMBUTTON_H
#define CUSTOMBUTTON_H
#include <QPushButton>
#include <QString>
#include "styleDefine.h"

typedef enum _PBN_STYLE_TYPE_
{
    PBN_STYLE_GREEN = 0,    // 绿色
    PBN_STYLE_WHITE = 1,    // 白色
    PBN_STYLE_BLUE  = 2     // 蓝色
}PBN_STYLE_TYPE;

class CustomButton : public QPushButton
{
public:
    CustomButton(const QString& normalIconPath, const QString& hoverIconPath, QWidget* parent = nullptr)
        : QPushButton(parent), m_strNormalIcon(normalIconPath), m_strHoverIcon(hoverIconPath)
    {
        setStyleSheet("QPushButton { border: none; background-color: transparent; }");
        setIcon(QIcon(m_strNormalIcon));
       // setIconSize(QSize(35, 35)); // 设置图标大小

    }

protected:
    void enterEvent(QEvent *event) override {
        QPushButton::enterEvent(event);
        setIcon(QIcon(m_strHoverIcon));
    }

    void leaveEvent(QEvent *event) override {
        QPushButton::leaveEvent(event);
        setIcon(QIcon(m_strNormalIcon));
    }

private:
    QString m_strNormalIcon;
    QString m_strHoverIcon;
};

class FluButton : public QPushButton
{
    Q_OBJECT
public:
    FluButton(QWidget* parent = nullptr, PBN_STYLE_TYPE nType = PBN_STYLE_GREEN)
        : QPushButton(parent)
        , m_nIndex(0)
        , m_bSelectStatus(false)
    {
        setFixedHeight(OBJ_FIXED_HEIGHT_NORMAL);
        setMinimumWidth(OBJ_FIXED_WIDTH_NORMAL);
        connect(this, SIGNAL(clicked()), this, SLOT(slt_clicked()));
        const QFont nCurFont = gFontConsolas;
        //nCurFont.setBold(true);
        setFont(nCurFont);

        if(PBN_STYLE_GREEN == nType)
        {
            setStyleSheet("QPushButton {"
                "    background-color: #4FB3BF;" // 淡青色
                "    color: #000000;"
                "    border: 1px solid #4FB3BF;"
                "    border-radius: 5px;"
                "}"
                "QPushButton:hover {"
                "    background-color: #2D8E99;" // 鼠标悬停时的颜色
                "}"
                "QPushButton:pressed {"
                "    background-color: #1A6C72;" // 按下时的颜色
                "}");
        }
        else if(PBN_STYLE_WHITE == nType)
        {
            setStyleSheet("QPushButton {"
                "    background-color: #fbfbfb;" // 白色
                "    color: #000000;"
                "    border: 1px solid #0078D4;"
                "    border-radius: 5px;"
                "}"
                "QPushButton:hover {"
                "    background-color: #f2f2f2;" // 鼠标悬停时的颜色
                "}"
                "QPushButton:pressed {"
                "    background-color: #e6e6e6;" // 按下时的颜色
                "}");
        }
        else if(PBN_STYLE_BLUE == nType)
        {
            // 淡蓝色系列
            setStyleSheet("QPushButton {"
                "    background-color: #0078D4;" // Fluent UI 淡蓝色
                "    color: #000000;"
                "    border: 1px solid #0078D4;"
                "    border-radius: 5px;"
                "}"
                "QPushButton:hover {"
                "    background-color: #005A9E;" // 鼠标悬停时的颜色
                "}"
                "QPushButton:pressed {"
                "    background-color: #004578;" // 按下时的颜色
                "}");
        }
        else
        {
            ;
        }
    }
    virtual ~FluButton() {}
    // 设置按钮序号值
    void setIndex(const uint nIndex)
    {
        m_nIndex = nIndex;
    }

    // 设置按钮不被选中
    void setNoSelect()
    {
        m_bSelectStatus = false;
    }

    // 设置按钮被选中
    void setSelected()
    {
        m_bSelectStatus = true;
    }

    // 获取按钮是否被选中
    bool getSelected()
    {
        return m_bSelectStatus;
    }

    // 获取按钮序号值
    uint getIndex()
    {
        return m_nIndex;
    }
private slots:
    void slt_clicked()
    {
        setSelected();
        emit click_index(m_nIndex);
    }

signals:
    void click_index(uint);

private:
    uint m_nIndex;          // 按钮序号值
    bool m_bSelectStatus;   // 是否被点击选中
};


#endif
